package org.developer.es.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.developer.es.app.service.PmsBrandService;
import org.developer.es.domain.entity.PmsBrand;
import org.developer.es.infra.util.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 品牌管理Controller
 * Created by macro on 2019/4/19.
 */
@Api(tags = "PmsBrandController", description = "商品品牌管理")
@Controller
@RequestMapping("/brand")
public class PmsBrandController {
    @Autowired
    private PmsBrandService brandService;

    private static final Logger LOGGER = LoggerFactory.getLogger(PmsBrandController.class);

    @ApiOperation("获取所有品牌列表")
    @RequestMapping(value = "listAll", method = RequestMethod.GET)
    @ResponseBody
//    @PreAuthorize("hasAuthority('pms:brand:read')")
    public ResponseEntity<?> getBrandList() {
        return Results.success(brandService.listAllBrand());
    }

    @ApiOperation("添加品牌")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
//    @PreAuthorize("hasAuthority('pms:brand:create')")
    public ResponseEntity<?> createBrand(/* @RequestBody PmsBrand pmsBrand */) {
//        CommonResult commonResult;
//        int count = brandService.createBrand(pmsBrand);
//        if (count == 1) {
//            commonResult = CommonResult.success(pmsBrand);
//            LOGGER.debug("createBrand success:{}", pmsBrand);
//        } else {
//            commonResult = CommonResult.failed("操作失败");
//            LOGGER.debug("createBrand failed:{}", pmsBrand);
//        }
//        return commonResult;
        int i = 1/0;
        return Results.success();
    }
//
//    @ApiOperation("更新指定id品牌信息")
//    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
//    @ResponseBody
////    @PreAuthorize("hasAuthority('pms:brand:update')")
//    public CommonResult updateBrand(@PathVariable("id") Long id, @RequestBody PmsBrand pmsBrandDto, BindingResult result) {
//        CommonResult commonResult;
//        int count = brandService.updateBrand(id, pmsBrandDto);
//        if (count == 1) {
//            commonResult = CommonResult.success(pmsBrandDto);
//            LOGGER.debug("updateBrand success:{}", pmsBrandDto);
//        } else {
//            commonResult = CommonResult.failed("操作失败");
//            LOGGER.debug("updateBrand failed:{}", pmsBrandDto);
//        }
//        return commonResult;
//    }
//
//    @ApiOperation("删除指定id的品牌")
//    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
//    @ResponseBody
////    @PreAuthorize("hasAuthority('pms:brand:delete')")
//    public CommonResult deleteBrand(@PathVariable("id") Long id) {
//        int count = brandService.deleteBrand(id);
//        if (count == 1) {
//            LOGGER.debug("deleteBrand success :id={}", id);
//            return CommonResult.success(null);
//        } else {
//            LOGGER.debug("deleteBrand failed :id={}", id);
//            return CommonResult.failed("操作失败");
//        }
//    }

}
